def pivotIndex(nums: list[int]) -> int:
    total_sum = sum(nums)
    prefix_sum = 0
    for idx in range(len(nums)):
        # 左边和 == 右边和
        if prefix_sum == total_sum - prefix_sum - nums[idx]:
            return idx
        prefix_sum += nums[idx]
    return -1


nums = [1, 7, 3, 6, 5, 6]
# nums = [1, 2, 3]
# nums = [2, 1, -1]
print(pivotIndex(nums))
